﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ITAP.ContourBuilder.Components;

namespace ITAP.ContourBuilder.GUI
{
    internal delegate void TextDialogChangedDelegate();
    public partial class FormEnterText : Form
    {
        public TextRenderType TextType
        {
            get
            {
                if (comboBoxTextType.SelectedIndex == 0)
                    return TextRenderType.UseModelTextSize;
                else
                    return TextRenderType.UseScreenTextSize;
            }
        }

        internal event TextDialogChangedDelegate TextDialogChanged;
        private Font font = new Font("Arial", 10);
        private Color color = Color.Black;

        public Color TextColor
        {
            get { return color; }
        }

        public Font TextFont
        {
            get
            {
                return font;
            }
        }

        public string EnteredText
        {
            get
            {
                return this.textBox.Text;
            }
        }

        public FormEnterText()
        {
            InitializeComponent();
            comboBoxTextType.Items.Add("Относительный");
            comboBoxTextType.Items.Add("Абсолютный");
            comboBoxTextType.SelectedIndex = 0;
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            this.Close();
        }

        private void buttonFont_Click(object sender, EventArgs e)
        {
            FontDialog dialog = new FontDialog();
            if (dialog.ShowDialog() != DialogResult.OK)
                return;

            font = dialog.Font;
            if (this.TextDialogChanged != null)
                this.TextDialogChanged.Invoke();

        }

        private void buttonColor_Click(object sender, EventArgs e)
        {
            ColorDialog dialog = new ColorDialog();
            if (dialog.ShowDialog() != DialogResult.OK)
                return;

            this.color = dialog.Color;
            if (this.TextDialogChanged != null)
                this.TextDialogChanged.Invoke();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void textBox_TextChanged(object sender, EventArgs e)
        {
            if (this.TextDialogChanged != null)
                this.TextDialogChanged.Invoke();
        }

        private void comboBoxTextType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.TextDialogChanged != null)
                this.TextDialogChanged.Invoke();
        }
    }
}
